package com.example.lenovo.test02;

import android.content.Intent;
import android.content.res.Configuration;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ConfigurationTest extends AppCompatActivity {

    EditText et1;
    EditText et2;
    EditText et3;
    EditText et4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_configuration_test);

        // 获取应用configuration界面中的界面组件
        et1 = findViewById(R.id.ori);
        et2 = findViewById(R.id.navigation);
        et3 = findViewById(R.id.touch);
        et4 = findViewById(R.id.mnc);
        Button bn = findViewById(R.id.bn);

        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取系统的configuration对象
                Configuration cfg=getResources().getConfiguration();
                String screen=cfg.orientation==Configuration.ORIENTATION_LANDSCAPE
                        ?"横屏":"竖屏";
                et1.setText(screen);
                String mncCode=cfg.mnc+"";
                et4.setText(mncCode);
                String naviName=cfg.orientation==Configuration.NAVIGATION_NONAV ?"没有方向控制"
                        :cfg.orientation==Configuration.NAVIGATION_WHEEL ?"滚轮控制方向"
                        :cfg.orientation==Configuration.NAVIGATION_DPAD ?"方向键控制方向"
                        :"轨迹球控制方向";
                et2.setText(naviName);
                String touchName=cfg.touchscreen==Configuration.TOUCHSCREEN_NOTOUCH ?"无触摸屏":"支持触摸屏";
                et3.setText(touchName);
            }
        });
        //返回主界面
        Button btn_back=findViewById(R.id.back);
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ConfigurationTest.this,MainActivity.class);
                startActivity(intent);
            }
        });

    }
}
